﻿using System;
namespace Xroad.Eu.Xsd.Identifiers {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="XRoadClientIdentifierType", Namespace="http://x-road.eu/xsd/identifiers", Target=typeof(XRoadClientIdentifierType))]
    public class XRoadClientIdentifierTypeSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected XRoadClientIdentifierType clazz;
        
        public XRoadClientIdentifierTypeSerializer(XRoadClientIdentifierType clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXmlAttributes(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXmlAttributes(Writer);
            if ((clazz.ObjectType != null)) {
                Writer.WriteAttributeString(Writer.LookupPrefix("http://x-road.eu/xsd/identifiers"), "objectType", "http://x-road.eu/xsd/identifiers", new global::Xroad.Eu.Xsd.Identifiers.XRoadObjectType(clazz.ObjectType).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.AttributeRequiredException(">>XRoadClientIdentifierType>objectType");
            }
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement(Writer.LookupPrefix("http://x-road.eu/xsd/identifiers"), "xRoadInstance", "http://x-road.eu/xsd/identifiers");
            if (clazz.XRoadInstance!=null) {
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.XRoadInstance))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : XRoadInstance");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement(Writer.LookupPrefix("http://x-road.eu/xsd/identifiers"), "memberClass", "http://x-road.eu/xsd/identifiers");
            if (clazz.MemberClass!=null) {
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.MemberClass))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : MemberClass");
            }
            Writer.WriteEndElement();
            Writer.WriteStartElement(Writer.LookupPrefix("http://x-road.eu/xsd/identifiers"), "memberCode", "http://x-road.eu/xsd/identifiers");
            if (clazz.MemberCode!=null) {
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.MemberCode))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : MemberCode");
            }
            Writer.WriteEndElement();
            if (clazz.SubsystemCode!=null) {
                Writer.WriteStartElement(Writer.LookupPrefix("http://x-road.eu/xsd/identifiers"), "subsystemCode", "http://x-road.eu/xsd/identifiers");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.SubsystemCode))).ToString());
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXmlAttributes(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXmlAttributes(Reader);
            var objectTypeValue = Reader.GetAttribute("objectType", "http://x-road.eu/xsd/identifiers");
            if ((objectTypeValue != null)) {
                clazz.ObjectType = new global::Xroad.Eu.Xsd.Identifiers.XRoadObjectType(objectTypeValue);
            }
            else {
                throw new global::Xtee.Core.Exceptions.AttributeRequiredException(">>XRoadClientIdentifierType>objectType");
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="xRoadInstance") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>xRoadInstance");
                }
                clazz.XRoadInstance = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("xRoadInstance", "http://x-road.eu/xsd/identifiers")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>xRoadInstance", Reader.LocalName);
            }
            if (Reader.LocalName=="memberClass") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>memberClass");
                }
                clazz.MemberClass = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("memberClass", "http://x-road.eu/xsd/identifiers")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>memberClass", Reader.LocalName);
            }
            if (Reader.LocalName=="memberCode") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>memberCode");
                }
                clazz.MemberCode = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("memberCode", "http://x-road.eu/xsd/identifiers")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>>memberCode", Reader.LocalName);
            }
            if (Reader.LocalName=="subsystemCode") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>>subsystemCode");
                }
                clazz.SubsystemCode = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("subsystemCode", "http://x-road.eu/xsd/identifiers")).Value;
            }
        }
    }
}
